﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BitcoinTrading.Data
{
    public class DataArbitrage
    {

        public const string TABLE_ACC_KORBIT_ASK = "ACC_KORBIT_ASK";
        public const string TABLE_ACC_KORBIT_BID = "ACC_KORBIT_BID";
        public const string TABLE_ACC_BTCE_ASK = "ACC_BTCE_ASK";
        public const string TABLE_ACC_BTCE_BID = "ACC_BTCE_BID";
        public const string TABLE_MARGINBUY = "MARGINBUY";
        public const string TABLE_MARGINSELL = "MARGINSELL";

        public const string COLUMN_ACC_BTCPRICE = "BTCPRICE";
        public const string COLUMN_ACC_BTCPRICE_AVG = "BTCPRICE_AVG";
        public const string COLUMN_ACC_BTCAMOUNT = "BTCAMOUNT";
        public const string COLUMN_EST_PER_INCOME = "EST_PER_INCOME";
        public const string COLUMN_EST_BTCAMOUNT = "BTCAMOUNT";
        public const string COLUMN_EST_BUY_BTCPRICE = "BUY_BTCPRICE";
        public const string COLUMN_EST_SELL_BTCPRICE = "SELL_BTCPRICE";


        DataSet _ds;

        public DataArbitrage()
        {
            Initialized();
        }

        private void Initialized()
        {
            DataTable dt;
            DataColumn col;

            _ds = new DataSet("TARGET");

            //누적 평균매수/매도가 - 수량 테이블 생성
            dt = new DataTable(TABLE_ACC_KORBIT_ASK);
            col = dt.Columns.Add();
            col.ColumnName = COLUMN_ACC_BTCPRICE;
            col.DataType = System.Type.GetType("System.Decimal");
            col = dt.Columns.Add();
            col.ColumnName = COLUMN_ACC_BTCPRICE_AVG;
            col.DataType = System.Type.GetType("System.Decimal");
            col = dt.Columns.Add();
            col.ColumnName = COLUMN_ACC_BTCAMOUNT;
            col.DataType = System.Type.GetType("System.Decimal");
            _ds.Tables.Add(dt);

            dt = _ds.Tables[TABLE_ACC_KORBIT_ASK].Clone();
            dt.TableName = TABLE_ACC_KORBIT_BID;
            _ds.Tables.Add(dt);

            dt = _ds.Tables[TABLE_ACC_KORBIT_ASK].Clone();
            dt.TableName = TABLE_ACC_BTCE_ASK;
            _ds.Tables.Add(dt);

            dt = _ds.Tables[TABLE_ACC_KORBIT_ASK].Clone();
            dt.TableName = TABLE_ACC_BTCE_BID;
            _ds.Tables.Add(dt);

            //매수/매도 차익시 이익 계산
            dt = new DataTable(TABLE_MARGINBUY);
            col = dt.Columns.Add();
            col.ColumnName = "EST_PER_INCOME";
            col.DataType = System.Type.GetType("System.Decimal");
            col = dt.Columns.Add();
            col.ColumnName = "BTCAMOUNT";
            col.DataType = System.Type.GetType("System.Decimal");
            col = dt.Columns.Add();
            col.ColumnName = "BUY_BTCPRICE";
            col.DataType = System.Type.GetType("System.Decimal");
            col = dt.Columns.Add();
            col.ColumnName = "SELL_BTCPRICE";
            col.DataType = System.Type.GetType("System.Decimal");
            _ds.Tables.Add(dt);

            dt = _ds.Tables[TABLE_MARGINBUY].Clone();
            dt.TableName = TABLE_MARGINSELL;
            _ds.Tables.Add(dt);
        }

        public void SetDataTable(string strTableName, DataTable dt)
        {
            if (_ds.Tables.Contains(strTableName))
            {
                _ds.Tables[strTableName].Clear();
                _ds.Tables[strTableName].Merge(dt);
            }
        }

        public DataTable Tables(string strTableName)
        {
            DataTable objReturn = null;

            if (_ds.Tables.Contains(strTableName))
            {
                objReturn = _ds.Tables[strTableName];
            }

            return objReturn;
        }
        
    }


}
